#include "stdafx.h"
#include "TGRxObject.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

TGRxObject::TGRxObject()
{

}

TGRxObject::~TGRxObject()
{

}

TGRxClass* TGRxObject::desc()
{
	TGRxDictionary * pRxDictionary = rxSysRegistry();
	if (pRxDictionary != NULL)
	{
		TGRxClass * pRxClass = NULL; 
		pRxClass = (TGRxClass*)((TGRxDictionary *)pRxDictionary->at(TGRX_CLASS_DICTIONARY))->at(TGRX_TGRXOBJECTCLASS);
		return pRxClass;
	}
	return NULL;
}

TGRxObject* TGRxObject::cast(const TGRxObject * pInPtr)
{
	return ((pInPtr == NULL) || !pInPtr->isKindOf(TGRxObject::desc()))
			? NULL : (TGRxObject*)pInPtr;
}

TGRxClass* TGRxObject::isA() const
{
	TGRxDictionary * pRxDictionary = rxSysRegistry();
	if (pRxDictionary != NULL)
	{
		TGRxClass * pRxClass = NULL; 
		pRxClass = (TGRxClass*)((TGRxDictionary *)pRxDictionary->at(TGRX_CLASS_DICTIONARY))->at(TGRX_TGRXOBJECTCLASS);
		return pRxClass;
	}
	return NULL;
}

TGRxObject*	TGRxObject::clone() const
{
	TGRxObject * pRxObject = new TGRxObject;
	pRxObject->copyFrom(this);
	return pRxObject;
}

TG::ErrorStatus	TGRxObject::copyFrom(const TGRxObject* other)
{
	return TG::eOk;
}

BOOL TGRxObject::isEqualTo(const TGRxObject * other) const
{
	return TRUE;
}

BOOL TGRxObject::isKindOf(const TGRxClass * pClass) const
{
	if (pClass == NULL)
	{
		return FALSE;
	}
	
	TGRxClass * pRxClass = isA();
	while(pRxClass != NULL)
	{
		if (pRxClass == pClass)
		{
			return TRUE;
		}
		pRxClass = pRxClass->myParent();
	}
	return FALSE;
}
